package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.community.GetCommunityBean;
import com.xinfu.newproject.bean.community.GetCommunityBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.community.GetCommunityModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class GetCommunityPresenter {
    private IView.IGetCommunityView mIGetCommunityView;

    private GetCommunityModel mGetCommunityModel;

    public GetCommunityPresenter(IView.IGetCommunityView iGetCommunityView) {
        this.mIGetCommunityView = iGetCommunityView;
        mGetCommunityModel = new GetCommunityModel();
    }

    /**
     * 登录
     */
    public void getCommunity() {

        mIGetCommunityView.showProgress();

        GetCommunityBody getCommunityBody = new GetCommunityBody(mIGetCommunityView.header());

        mGetCommunityModel.getCommunity(getCommunityBody, new MyCallBack<GetCommunityBean>() {
            @Override
            public void onSuccess(GetCommunityBean getCommunityBean) {
                mIGetCommunityView.hideProgress();

                if (getCommunityBean.isSuccess()) {
                    mIGetCommunityView.getData(getCommunityBean);
                } else {
                    mIGetCommunityView.showToast(getCommunityBean.getMessage());
                }

            }

            @Override
            public void onError(String header, String message) {
                mIGetCommunityView.hideProgress();
                mIGetCommunityView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIGetCommunityView.closeDispose(disposable);
            }
        });


    }


//    private Map<String, String> createParaMap() {
//        Map<String, String> paraMap = new HashMap<>();
//        paraMap.put("userName", mIRegisterView.getUserName());
//        return paraMap;
//    }

}
